package startup;


import core.SimpleContextConfig;
import org.apache.catalina.*;
import org.apache.catalina.connector.http.HttpConnector;
import org.apache.catalina.core.*;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.startup.ContextConfig;

public class Bootstrap {
    public static void main(String[] args) {
        System.setProperty("catalina.base", System.getProperty("user.dir"));

        Context context = new StandardContext();
        context.setPath("/app1");
        context.setDocBase("app1");

        LifecycleListener listener = new ContextConfig();
        ((Lifecycle) context).addLifecycleListener(listener);

        Loader loader = new WebappLoader();
        context.setLoader(loader);

        Host host = new StandardHost();
        host.addChild(context);
        host.setName("localhost");
        host.setAppBase("webapps");

        Connector connector = new HttpConnector();
        connector.setContainer(host);

        try {
            connector.initialize();
            ((Lifecycle)connector).start();
            ((Lifecycle)host).start();
            Container[] children = context.findChildren();
            for (Container c : children) {
                System.out.println(c.getName());
            }
            System.in.read();
            ((Lifecycle)host).stop();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
